/*
你是完全没有理解：
例如：[1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1]
连续正确1段：1，
连续正确2段：2，
连续正确3段：2，
连续正确4段：1，

连续错误1段：2，
连续正确2段：2，
连续正确3段：0，
连续正确4段：1，

这么说你懂了吗？
*/

const _ = require("lodash");
const fs = require("fs");
const path = require("path");

// 统计连续正确和连续错误的段落长度
const calculateConsecutiveCounts = require("../utils/calculateConsecutiveCounts.js");
// 统计连续段长度出现的频率
const getLengthFrequency = require("../utils/getLengthFrequency.js");
// 格式化输出
const formatFrequency = require("../utils/formatFrequency.js");
// 计算正确段和错误段的总长度
const calcTotalLength = require("../utils/calcTotalLength.js");

// 读取项目根目录下 data/temp_accuracy_result.json 的数据
// 该文件存储了一个由 0 和 1 组成的数组，1 表示预测正确，0 表示预测错误
const dataPath = path.resolve(__dirname, "../data/temp_accuracy_result.json");
// const data = JSON.parse(fs.readFileSync(dataPath, "utf-8"));
const data = [1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1]

console.log(`数据总长度: ${data.length}`);

// 统计连续正确和连续错误的段落长度
// prettier-ignore
const { consecutiveCorrect, consecutiveIncorrect } = calculateConsecutiveCounts(data);

console.log(consecutiveCorrect, consecutiveIncorrect)

const correctFrequency = getLengthFrequency(consecutiveCorrect);
const incorrectFrequency = getLengthFrequency(consecutiveIncorrect);

const formattedCorrectFrequency = formatFrequency(correctFrequency);
const formattedIncorrectFrequency = formatFrequency(incorrectFrequency);

// 打印结果
console.log("正确：", formattedCorrectFrequency);
console.log("错误：", formattedIncorrectFrequency);

const totalCorrectLength = calcTotalLength(formattedCorrectFrequency);
const totalIncorrectLength = calcTotalLength(formattedIncorrectFrequency);
const totalLength = totalCorrectLength + totalIncorrectLength;

console.log("正确段总长度：", totalCorrectLength);
console.log("错误段总长度：", totalIncorrectLength);
console.log("正确段和错误段总长度之和：", totalLength);
